package com.pro.controller;

import com.pro.pojo.JsComment;
import com.pro.pojo.JsMicrocircle;
import com.pro.pojo.JsonData;
import com.pro.service.JsNewMicrocircleCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author cyj
 * @date $ $
 * @content :
 */
@RestController
@RequestMapping("/microComment")
public class JsNewMicrocircleCommentController {

    @Autowired
    private JsNewMicrocircleCommentService service;

    /**
     * @author cyj
     * @date 2022.3.30$ 19.15$
     * @content : 统计前台的评论数
     */
    @RequestMapping("/getUserComment")
    public JsonData getUserComment(Integer id){
        JsMicrocircle comment = service.getUserComment(id);
        return comment!=null?JsonData.buildSuccess(comment):JsonData.buildError("服务器错误");
    }
    /**
     * @author cyj
     * @date 2022.3.30$ 19.03$
     * @content : 统计前台的评论数
     */
    @RequestMapping("/getBeforeComment")
    public JsonData getBeforeComment(Integer id){
        JsMicrocircle comment = service.getBeforeComment(id);
        return comment!=null?JsonData.buildSuccess(comment):JsonData.buildError("服务器错误");
    }
    /**
     * @author cyj
     * @date 2022.3.30$ 18.54$
     * @content : 统计前台的评论数
     */
    @RequestMapping("/countUserComment")
    public JsonData countUserComment(Integer type, String status){
        Integer count = service.countUserComment(type,status);
        return count!=null?JsonData.buildSuccess(count):JsonData.buildError("服务器错误");
    }

    /**
     * @author cyj
     * @date 2022.3.30$ 18.34$
     * @content : 获取后台人员评论计数
     */
    @RequestMapping("/getUserTable")
    public JsonData getUserTable(Integer type, String status, Integer page, Integer limit){
        List<JsComment> comments = service.getUserTable(type,status,page,limit);
        Integer count = service.countComm(type,status,"2",null);
        return comments!=null?JsonData.buildSuccess(comments,count):JsonData.buildError("服务器错误");
    }

    /**
     * @author cyj
     * @date 2022.3.30$ 16.29$
     * @content : 获取后台人员评论计数
     */
    @RequestMapping("/getBeforeTable")
    public JsonData getBeforeTable(Integer type, String status, Integer page, Integer limit){
        List<JsComment> comments = service.getBeforeTable(type,status,page,limit);
        Integer count = service.countComm(type,status,"1",null);
        return comments!=null?JsonData.buildSuccess(comments,count):JsonData.buildError("服务器错误");
    }
    /**
     * @author cyj
     * @date 2022.3.30$ 15.56$
     * @content : 统计数据表格
     */
    @RequestMapping("/countMicroComment")
    public JsonData countCourseComment(Integer type,String status,String userType,String commentDate){
        System.err.println(commentDate);
        Integer history = service.countComm(type,status,userType,null);
        Integer historyPeo = service.countPeo(type,status,userType,null).size();
        Integer today = service.countComm(type,status,userType,commentDate);
        Integer todayPeo = service.countPeo(type,status,userType,commentDate).size();
        List list = new ArrayList();
        list.add(history);
        list.add(historyPeo);
        list.add(today);
        list.add(todayPeo);
        return list!=null?JsonData.buildSuccess(list):JsonData.buildError("服务器错误");
    }

    /**
     * @author cyj
     * @date 2022.3.30$ 13.39$
     * @content : 统计前台的评论数
     */
    @RequestMapping("/countBeforeComment")
    public JsonData countBeforeComment(Integer type, String status){
        Integer count = service.countBeforeComment(type,status);
        return count!=null?JsonData.buildSuccess(count):JsonData.buildError("服务器错误");
    }
}
